import axios from "axios";
const defaultAxios = axios.create({
  baseURL: "/api",
  timeout: 1000,
});
defaultAxios.interceptors.request.use((config) => {
  return config;
});
defaultAxios.interceptors.response.use(
  (res) => {
    return res.data;
  },
  (error) => {
    let code = error.response;
    if (code == 301) {
      console.log("该页面已经移动");
    } else if (code == 302) {
      console.log("该页面临时移动");
    } else if (code == 401) {
      console.log("token过期");
    } else if (code == 403) {
      console.log("服务器拒绝请求");
    } else if (code == 404) {
      console.log("token过期该页面不存在");
    } else {
      // 发送请求时出了点问题
      console.log("Error", error.message);
    }
  }
);
export { defaultAxios };
